package com.example.androidmaze;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

public class MazePanel extends View  {
//	/* Panel operates a double buffer see
//	 * http://www.codeproject.com/Articles/2136/Double-buffer-in-standard-Java-AWT
//	 * for details
//	 */
//	Image bufferImage ;
	private static final String TAG = "MazePanel";
	Config config = Config.ARGB_8888;
	Bitmap mazeBmap = Bitmap.createBitmap(768, 768, config);
	Paint paint = new Paint();
	Canvas mazeCanvas = new Canvas(mazeBmap);
	int i = 0;
	
//	public MazePanel(Context context) {
//		
//		super(context) ;
//		this.setFocusable(false) ;
//		Log.v(TAG, "0");
//		//FirstPersonDrawer.setBitmap(mPanel);
//		
//	}
	public MazePanel(Context context) {
		super(context);
		this.setFocusable(false);
		Log.v(TAG, "0");
		
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		
		
		paint.setColor(Color.BLUE);

		//super.onDraw(canvas);
		Log.v(TAG, "drawing on canvas, i= " + i);
		canvas.drawBitmap(mazeBmap, 0, 0, paint);
		//canvas.drawColor(Color.RED);
		//canvas.drawBitmap(mPanel, 0, 0, paint);
		
	}
	
	public void drawToCanvas(Canvas canvas) {
		mazeCanvas = canvas;
	}
	public void giveBitmap(Bitmap bitmap) {
		i++;
		mazeBmap = bitmap;
	}
//	@Override
//	public void update(Graphics g) {
//		paint(g) ;
//	}
//	@Override
//	public void paint(Graphics g) {
//		g.drawImage(bufferImage,0,0,null) ;
//	}
//	/*
//	public void setBufferImage(Image buffer) {
//		bufferImage = buffer ;
//	}
//	*/
//	public void initBufferImage() {
//		bufferImage = createImage(Constants.VIEW_WIDTH, Constants.VIEW_HEIGHT);
//		if (null == bufferImage)
//		{
//			System.out.println("Error: creation of buffered image failed, presumedly container not displayable");
//		}
//	}
//	public Graphics getBufferGraphics() {
//		if (null == bufferImage)
//			initBufferImage() ;
//		return bufferImage.getGraphics() ;
//	}
	public void update() {
		//paint(getGraphics()) ;
		Log.v("MazePanel", "update()");
		invalidate();
	}
}
